import turtle
import math

def draw_star1(pen: turtle.Turtle, x = 0, y = 0, radius = 100, heading_angle = 90, color = "yellow"):

    pen.color(color)

    # 调整方向
    pen.setheading(heading_angle) 

    pen.penup()
    pen.teleport(x, y) # 到圆心
    pen.pendown()
    pen.forward(radius)
    point1 = pen.pos()
    print("point1:", point1)
    pen.teleport(x, y) # 到圆心
    pen.right(360 / 5) # 点2方向
    pen.forward(radius)
    point2 = pen.pos()
    print("point2:", point2)
    pen.teleport(x, y) # 到圆心
    pen.right(360 / 5) # 点3方向
    pen.forward(radius)
    point3 = pen.pos()
    print("point3:", point3)
    pen.teleport(x, y) # 到圆心
    pen.right(360 / 5) # 点4方向
    pen.forward(radius)
    point4 = pen.pos()
    print("point4:", point4)
    pen.teleport(x, y) # 到圆心
    pen.right(360 / 5) # 点5方向
    pen.forward(radius)
    point5 = pen.pos()
    print("point5:", point5)

    # 画五角星
    pen.penup()
    pen.teleport(point1[0], point1[1]) # 到第一个点
    pen.pendown()
    pen.pensize(1.5)
    pen.fillcolor("yellow")
    pen.begin_fill() # 开始填充
    pen.goto(point3)
    pen.goto(point5)
    pen.goto(point2)
    pen.goto(point4)
    pen.goto(point1)
    pen.end_fill() # 结束填充

def draw_star2(pen: turtle.Turtle, x = 0, y = 0, radius = 100, heading_angle = 90, color = "yellow"):

    pen.color(color)

    # 调整方向
    pen.setheading(heading_angle) 

    pen.penup()
    pen.teleport(x, y) # 到圆心
    pen.pendown()
    pen.forward(radius)
    point1 = pen.pos()
    print("point1:", point1)
    pen.teleport(x, y) # 到圆心
    pen.right(360 / 5) # 点2方向
    pen.forward(radius)
    point2 = pen.pos()
    print("point2:", point2)
    pen.teleport(x, y) # 到圆心
    pen.right(360 / 5) # 点3方向
    pen.forward(radius)
    point3 = pen.pos()
    print("point3:", point3)
    pen.teleport(x, y) # 到圆心
    pen.right(360 / 5) # 点4方向
    pen.forward(radius)
    point4 = pen.pos()
    print("point4:", point4)
    pen.teleport(x, y) # 到圆心
    pen.right(360 / 5) # 点5方向
    pen.forward(radius)
    point5 = pen.pos()
    print("point5:", point5)

    # 画五角星
    pen.penup()
    pen.teleport(x, y) # 到圆心
    pen.pendown()
    pen.fillcolor("yellow")
    pen.begin_fill() # 开始填充
    pen.goto(point1)
    pen.goto(point3)
    pen.goto(x, y) # 到圆心
    pen.end_fill() # 结束填充
    pen.begin_fill() # 开始填充
    pen.goto(point2)
    pen.goto(point4)
    pen.goto(x, y) # 到圆心
    pen.end_fill() # 结束填充
    pen.begin_fill() # 开始填充
    pen.goto(point3)
    pen.goto(point5)
    pen.goto(x, y) # 到圆心
    pen.end_fill() # 结束填充
    pen.begin_fill() # 开始填充
    pen.goto(point4)
    pen.goto(point1)
    pen.goto(x, y) # 到圆心
    pen.end_fill() # 结束填充
    pen.begin_fill() # 开始填充
    pen.goto(point5)
    pen.goto(point2)
    pen.goto(x, y) # 到圆心
    pen.end_fill() # 结束填充

def draw_star3(pen: turtle.Turtle, x = 0, y = 0, radius = 100, heading_angle = 90, color = "yellow"):

    pen.color(color)

    # 调整方向
    pen.setheading(heading_angle) 

    for i in range(5):
        pen.penup()
        pen.teleport(x, y) # 到圆心
        pen.forward(radius) # 走到圆边
        pen.left(180) # 掉头
        pen.pendown()
        bpos = pen.pos() # 下笔位置
        pen.begin_fill() # 开始填充
        pen.forward(radius) # 到圆心
        pen.left(180 - 360 / 5 * 2) # 
        pen.forward(radius)
        pen.goto(bpos) # 回到下笔位置
        pen.left(360 / 5) # 转向下一个点
        pen.end_fill()

def draw_star4(pen: turtle.Turtle, x = 0, y = 0, radius = 100, heading_angle = 90, color = "yellow"):

    pen.color(color)

    # 调整方向
    pen.setheading(heading_angle) 

    # 根据半径计算边长
    side = radius * math.sin(math.radians(72)) / (1 + math.sin(math.radians(18)))

    pen.penup() # 提起笔
    pen.teleport(x, y) # 到圆心
    pen.forward(radius) # 到圆边
    pen.right(180 - 18) # 掉头后便转18度
    pen.pendown() # 不放下笔时不画边框，但会填充

    ## 开始画五角星
    pen.begin_fill() # 开始填充
    for _ in range(5):
        pen.forward(side)
        pen.left(72)
        pen.forward(side)
        pen.right(144)
    pen.end_fill() # 结束填充
    ## 结束画五角星

def main():
    # 设置画布
    width = 900
    height = 600
    screen = turtle.getscreen()
    screen.title("画五角星")
    screen.setup(width + 100, height + 100)

    # 设置画笔
    pen = turtle.getpen()
    pen.shape("turtle")
    pen.speed(1) # 速度：“fastest”: 0、“fast”: 10、“normal”: 6、“slow”: 3、“slowest”: 1

    # 绘制红色背景
    pen.teleport(-width/2, height/2)
    pen.color("red")
    pen.begin_fill()
    for _ in range(2):
        pen.forward(width)
        pen.right(90)
        pen.forward(height)
        pen.right(90)
    pen.end_fill()
    pen.color("black")

    pen.speed(1)  # 统一设置为最快速度
    # 绘制四个五角星
    draw_star1(pen, - width / 2 / 2, height / 2 /2)  # 左上角
    draw_star2(pen, - width / 2 / 2, - height / 2 /2)  # 左下角
    draw_star3(pen, width / 2 / 2, - height / 2 /2)  # 右下角
    draw_star4(pen, width / 2 / 2, height / 2 /2)  # 右上角

    pen.hideturtle()
    screen.mainloop()

if __name__ == "__main__":
    main()